<?php
/**
 * RedXenon Framework
 * 
 * LICENSE
 * 
 * This source file is subject to the New BSD license that is bundled
 * with this package in the file LICENSE.txt
 * A copy of this license can be found in the world-wide-web at this URL:
 * http://www.redxenon.com/license/new-bsd-license.txt
 */

/** Abstract class*/
require_once ('RXFileManager.php');

/**
 * RedXenon File (RXFileManagerINI.php)
 * Defines routines to gather data from INI files (like php.ini)
 * 
 * @category RedXenon
 * @package RedXenon_File
 * @copyright Copyright (c) 2011 Red Xenon (http://www.redxenon.com)
 * @version $Id: RXFileManagerINI.php 1.0 2011-04-25 $ 
 */
class RXFileManagerINI extends RXFileManager {
	
	/**
	 * Array containing the data included in the INI File
	 * @var Array
	 */
	private $data;
	
	/**
	 * Constructor of a new RXFileManagerINI Object
	 * @param $filePath String to the file
	 */
	public function __construct($filePath){
		try{
			self::setNewFile($filePath);
			if(is_a($this->file, "RXFile")){
				if(strcasecmp($this->file->getExtension(), "INI") == 0){
					$this->data = parse_ini_file($filePath, TRUE);
				}else{
					throw new Exception("The File is not an INI and cannot be parsed as an INI file");
				}
			}
		}catch(Exception $e){
			throw new Exception("The INI file could not be parsed: ".$e->getMessage());
		}
	}
	
	/**
	 * Returns all the array parsed from the File
	 * @return Array | FALSE in case that the File could not be parsed
	 */
	public function getFullDataList(){
		return $this->data;
	}
	
	/**
	 * Returns an array with the elements contained in it
	 * @param String $category
	 */
	public function getData($category){
		return $this->data[$category];
	}
	
	/**
	 * Returns an element contained in a category passed by parameter
	 * @param String $category
	 * @param String $element
	 */
	public function getDataElement($category, $element){
		return $this->data[$category][$element];
	}
}

?>